package com.kunbo.cn.controller.core.message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import com.kunbo.cn.entity.core.inventory.Inventory;
import com.kunbo.cn.entity.core.message.LeavingMessage;
import com.kunbo.cn.service.core.inventory.InventoryService;
import com.kunbo.cn.service.core.message.LeavingMessageService;
import com.kunbo.cn.util.date.SDate;
import com.kunbo.cn.util.retu.CommonResult;

/**
 *
 * @author bjl  
 * @date 2019年4月25日 
 */
public class LeavingMessageController {
	@Autowired
    private JdbcTemplate jdbcTemplate;
	@Autowired
	private LeavingMessageService service;
	/**
	 * 添加库存单
	 * 
	 */
	@PostMapping("/add")
	public CommonResult add(LeavingMessage mes) {
		service.save(mes);
		return new CommonResult(true,"操作成功",null);
	}
	/**
	 * 生成库存编码
	 * 
	 */
	/*@GetMapping("/createCode")
	public String createCode(){
		 String prex = "KCD";
		 String suffix="1001";
		 int n=0;
			String sql="";
			sql +="select\r\n" ; 
			sql +=" MAX(autonomy) as au\r\n";
			sql +="FROM business_inventory_manage d\r\n";
			List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
			Integer t = (Integer) list.get(0).get("au");
			//Float lowerAmount=t-t1;
			String inventoryCode="";
			String time =sdf.format(new Date());
			if(t==null){
				System.out.println("***********tare**********");
				inventoryCode=prex+time+suffix;
			}else {
				int f=t+1;
				inventoryCode=prex+time+f;
			}
		return inventoryCode;
	}*/
	@GetMapping("/createCode")
	public String createCode(){
		 String prex = "KC";
		 String noticeCode= prex+SDate.getSystemDateYMDHMSToString();
		return noticeCode;
	}
	//暂时不用
/*	@PutMapping("/update")
	public CommonResult update(Inventory inventory) {
		service.update(inventory);
		return new CommonResult(true,"操作成功",null);
	}*/
	
	/**
	 *修改审核状态 
	 * 
	 *//*
	@PutMapping("/updateState")
	public CommonResult update1(Inventory carryOver) {
		service.updateExamineState(carryOver);
		return new CommonResult(true,"操作成功",null);
	}*/
	
	@DeleteMapping("/delete")
	public CommonResult delete(String id) {
		service.delete(id);
		return new CommonResult(true,"操作成功",null);
	}
	
	@GetMapping("/findById")
	public LeavingMessage findById(String id) {
		LeavingMessage d = service.findById(id);
		return d;
	}
	
	/**
	 *条件分页查询
	 * 
	 */
	@GetMapping("/findInventory")
	public Page<LeavingMessage> findLeavingMessage(Integer pageNo,Integer pageSize) {
		Page<LeavingMessage> page = service.findLeavingMessage(pageNo, pageSize);
		return page;
	}
}
